﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Drawing;

using Wxits.Data;
using Wxits.Helper;


public partial class Admin_CashList : BasePage_Grid
{
    private string _id = string.Empty;


    private int _PageSize
	{
		set { ViewState["PageSize"] = value; }
		get
		{
			return Convert.ToInt32(ViewState["PageSize"]);
		}
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
            DataCheck.CheckAuthority();

            string strSQL = @"select * from Sys_Common_Class_Detail where ClassId = 5";
            DataTable dt = DBAccess.ExecuteDataTable(strSQL);
            ddlType.DataSource = dt;
            ddlType.DataTextField = "name";
            ddlType.DataValueField = "value";
            ddlType.DataBind();
            ddlType.Items.Insert(0, new ListItem("全部", ""));

            _PageSize = 10;
			ShowData(0, _PageSize);			
		}
	}

	private void ShowData(long PageIndex, long PageSize)
	{


        string strSQL = @"SELECT a.*,b.NickName,b.Mobile,(SELECT NickName FROM Users WHERE UserId = a.FromUserId) AS FromUserName
                        ,(select Name from Sys_Common_Class_Detail where ClassId = 4 and value = a.TradeType) as TradeTypeTxt
                        ,(select Name from Sys_Common_Class_Detail where ClassId = 5 and value = a.BonusType) as BonusTypeTxt
                        ,'InOrOutTxt' = 	
                        CASE 
	                        WHEN a.InOrOut = 1 THEN '<--' 
	                        ELSE '-->'
                        END
                         FROM Mall_Users_Bonus_Cash a LEFT JOIN Users b ON a.UserId = b.UserId
					WHERE 1 = 1 ";


        if (!string.IsNullOrEmpty(txtName.Text.Trim()))
            strSQL += " AND (b.NickName like '%" + txtName.Text.Trim() + "%' or b.Mobile like '%" + txtName.Text.Trim() + "%')'";
        if (!string.IsNullOrEmpty(ddlType.SelectedValue))
            strSQL += " AND a.BonusType = '" + ddlType.SelectedValue + "' ";

        strSQL += " ORDER BY Id DESC";

        DataTable dt = DBAccess.ExecuteDataTable(strSQL);

        BindGrid(gvData, Navigator, PageIndex, PageSize, dt);
	}

	protected void Navigator_PageChanged(object sender, QHH.Web.UI.EventArg.NavigatorEventArgs e)
	{
		_PageSize = (int)e.PageSize;
		ShowData(e.NewPageIndex, _PageSize);
	}

	protected void Search_Click(object sender, EventArgs e)
	{
		ShowData(0, _PageSize);
	}


}
